<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>
	</head>

	<body>

		<!--面包屑导航 begin-->
		<div class="breadcrumbnav">
			<span class="layui-breadcrumb " lay-separator="·">
			  <a ><cite>首页</cite></a>
			  <a ><cite>库存管理</cite></a>
			  <a ><cite>当前库存</cite></a>
			</span>
		</div>
		<!--面包屑导航 end-->

		<div class="kit-doc">
			<!-- 标题 -->
			<div class="kit-doc-title">
				<fieldset>
					<legend>
						<a name="blockquote">库存</a>
					</legend>
				</fieldset>
			</div>

			<!-- 标题 end-->

			<!-- 概述 -->
			<div class="boderbox">
				<!--<div class="rowtop">-->
					<!--<a href="javascript:;" class="layui-btn addbtn" data-url="stock_up.html" data-icon="icon-tixing" data-title="库存上限提醒设置" kit-target data-id='81'>库存上限提醒设置</a>
					<a href="javascript:;" class="layui-btn addbtn" data-url="stock_down.html" data-icon="icon-tixing" data-title="库存下限提醒设置" kit-target data-id='82'>库存下限提醒设置</a>
					<a href="javascript:;" class="layui-btn addbtn" data-url="stock_inventory_profit.html" data-icon="icon-mendianyingkui" data-title="库存下限提醒设置" kit-target data-id='83'>商品自动盘亏盘盈</a>-->
					<!--<button class="layui-btn addbtn openwinbtn" data-method="addmang">新建库存信息</button>-->
						<button class="layui-btn addbtn openwinbtn layui-bg-blue hidediv" id="yeschoice"  data-method="yeschoice">确认选择</button>
					<!--<form class="layui-form searchform" action="" id="comSearchForm">
	<div class="layui-input-inline">
		<select name="city" lay-verify="">
			<option value="010">彬彬木业</option>
			<option value="021">彬彬木业</option>
			<option value="0571" selected>layim</option>
		</select>
	</div>
	<div class="layui-input-inline">
		<input type="text" name="text" required lay-verify="required" placeholder="输入关键字" autocomplete="off" class="layui-input">
	</div>
	<div class="layui-btn-group">
		<button class="layui-btn">搜索</button>
		<button class="layui-btn layui-btn-normal">重置</button>
	</div>
</form>
				</div>-->

				<div class="layui-tab-content notab">
					<div class="layui-tab-item layui-show">
						<table class="layui-table " lay-filter="table100" id="SNtable"></table>
					</div>
				</div>
				<!-- 
<div class="rowbottom rightrow">
  
        <div class="layui-btn-group">
          <button class="layui-btn" id="openstock">开单</button>
          <button class="layui-btn layui-btn-normal">打单</button>
        </div>
 
</div> -->

<script id="openbox1" type="text/html">
	<div class="alertbox layui-layer-wrap">
		<table class="alerttop">
			<tbody>
				<tr class="tabletitle">
					<td colspan="2">产品条码6948505400038在泰比胜总部仓库的库存周转率</td>
				</tr>
			</tbody>
		</table>
		<table class="layui-table" lay-skin="row ">
			<thead>
				<tr>
					<th>序号</th>
					<th>年度销售产品成本</th>
					<th>当年平均库存价值</th>
					<th>库存周转率</th>
				</tr>
			</thead>
			<tbody>

				<tr>
					<td>1</td>
					<td>1218000</td>
					<td>60900</td>
					<td>20</td>
				</tr>
			</tbody>
		</table>
	</div>
</script>

<script id="openbox2" type="text/html">
	<div class="alertbox layui-layer-wrap">
		<table class="alerttop">
			<tbody>
				<tr class="tabletitle">
					<td colspan="2">产品条码6948505400038在泰比胜总部仓库的积压统计</td>
				</tr>
			</tbody>
		</table>
		<table class="layui-table" lay-skin="row ">
			<thead>
				<tr>
					<th>序号</th>
					<th>本月积压</th>
					<th>季积压</th>
					<th>年积压</th>
				</tr>
			</thead>
			<tbody>

				<tr>
					<td>1</td>
					<td>2656</td>
					<td>60900</td>
					<td>212</td>
				</tr>
			</tbody>
		</table>
	</div>
</script>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/allajax.js"></script>
<script>

if(GetQueryString("urltype")){
				$("#yeschoice").show();
				
			}else{
				$("#yeschoice").hide();
			}
	layui.use(['layer', 'form', 'element', 'table', 'laydate', 'laypage'], function() {
		var layer = layui.layer,
			form = layui.form,
			element = layui.element,
			table = layui.table,
			laydate = layui.laydate,
			laypage = layui.laypage;

		//  目录查询全部树
		var tableArray = new Array();
		EEListFn(1, 100);

		function EEListFn(curr, limit) {
			AjaxPostFn('system/repository/select?page=' + curr + '&pagesize=' + limit, "{}", function(jsonData) {
				if(jsonData.pageInfo.size != 0) {

					$.each(jsonData.pageInfo.list, function(idx, obj) {
						objRepository = obj.bizRepository;
						objVo = obj.bizCommodityVo; //商品基础信息
						console.log(objRepository)
						tableArray.push({
							"id": objRepository.id,
							"operation": '<a class="layui-btn layui-btn-danger " lay-event="delthis" >删除</a>',
							"locationId": objRepository.locationId,
							"theNum": objRepository.theNum,
							"updateId": objRepository.updateId,
							"updateTime": getMyDate(objRepository.updateTime),
							"commodityNumber": objRepository.commodityNumber,
							"barCode": objRepository.barCode,
							"createTime": getMyDate(objRepository.createTime),
							"merchantNumber": objRepository.merchantNumber,
							"commodityId": objRepository.commodityId,
							"commodityName": objVo.commodityName,
							"homePhoto1": "<img src='" + IMGUrl + '' + objVo.homePhoto + "' alt='分类主图' class='classifyimg'>"
						});

					})

//					console.log(tableArray)
				}
				//    system/catalog/deletecatalogbyId

				//展示已知数据
				var tableIns = table.render({
					elem: '#SNtable',
					cols: [
						[ //标题栏
							{
								field: 'id',
								minWidth: '0%',
								width: '0%',
								type: 'space',
								style: 'display:none'
							},{type:'checkbox',fixed: 'left'}, {
								field: 'operation',
								width: 100,
								title: '操作'
							}, {
								field: 'locationId',
								width: 150,
								title: '库存地点' + modDot,
								edit: 'text'
							}, {
								field: 'commodityName',
								width: 150,
								title: '产品名称'
							}, {
								field: 'homePhoto1',
								width: 150,
								title: '主图'
							}, {
								field: 'theNum',
								width: 150,
								title: '库存数量' + modDot,
								edit: 'text'
							}, {
								field: 'commodityNumber',
								width: 150,
								title: '商品编码'
							}, {
								field: 'barCode',
								width: 150,
								title: '产品条码'
							}, {
								field: 'commodityId',
								width: 210,
								title: '商品id'
							}, {
								field: 'merchantNumber',
								width: 150,
								title: '商家编号'
							}, {
								field: 'updateId',
								width: 150,
								title: '库存最后改动人'
							}, {
								field: 'updateTime',
								width: 180,
								title: '库存最后改动时间'
							}, {
								field: 'createTime',
								width: 180,
								title: '出货时间'
							}

						]
					],
					data: tableArray,

					size: 'lg',
					height: 'full-250',
					even: true,
					page: true, //是否显示分页
					done: function() {
						//										laypage.render({
						//											elem: 'layui-table-page1' //注意，这里的 test1 是 ID，不用加 # 号
						//												,
						//											count: jsonData.pageInfo.total //数据总数，从服务端得到
						//												,
						//											jump: function(obj, first) {
						//												//首次不执行
						//												if(!first) {
						//													//do something
						//													EEListFn(obj.curr, obj.limit);
						//												}
						//											}
						//										});

						//图片点击放大
						TopimgFn();

					}
				}); //数据渲染结束
			})

		} //listfn结束

		//监听单元格编辑
		table.on('edit(table100)', function(obj) {
			var value = obj.value //得到修改后的值
				,
				data = obj.data //得到所在行所有键值
				,
				field = obj.field; //得到字段

			AjaxPostFn('system/repository/update', JSON.stringify(data), function(jsonData) {

				if(jsonData.htmlState.status == 200) {
					layer.msg("修改成功");
				}
			})

		});

		//监听表格内的按钮
		table.on('tool(table100)', function(obj) {
			var data = obj.data;
			if(obj.event === 'delthis') {
				layer.confirm('是否删除该条信息', function(index) {
					AjaxPostFn('system/repository/delete', "{'id':'" + data.id + "'}", function(jsonData) {
						if(jsonData.htmlState.status == 200) {
							layer.msg("删除成功");

						} else {}
					})
					obj.del();
					layer.close(index);
				});
			}
		});

		
		
		
		var tab = parent.tab;
		$('a').off('click').on('click', function() {
			var _that = $(this),
				_data = {
					title: _that.data('title'),
					icon: _that.data('icon'),
					id: _that.data('id'),
					url: _that.data('url')
				};
			tab.tabAdd(_data);
		});
		
		$('.openwinbtn').on('click', function() {
                    var othis = $(this),
                        method = othis.data('method');
                    active[method] ? active[method].call(this, othis) : '';
                });
		
		var active = {
		    addmang:function(){

				var addindex = layer.open({
				  type: 2,
				  title:"新建库存信息",
				  area: ['100%', '100%'],
				  maxmin: true,
				  shade: 0,
				  content: 'stock_new.html'
				});
				
			}
			
			,yeschoice:function(){ 

			 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			 	var checkStatus = table.checkStatus('SNtable')
			      ,data = checkStatus.data;
			      if(data.length < 1 ){
			      	layer.msg("请选择至少一件商品")
			      }else{
			      	
			   		
			      	var stockInstr ;
			      	$.each(data, function(idx,obj) {
			      		var tf = true;
						$.each(parent.$("#stockinTable tbody tr"),function(tridx,trobj){
							var thisBarcode = parent.$("#stockinTable tbody tr:eq("+idx+") td:eq(2)").html()
							if(thisBarcode === obj.barCode){
								tf =  false;
							}
//							console.log(idx)
						})
						if(tf){
							if(GetQueryString("urltype") == "offline"){
								//线下订单生成页面跳转而来
								
								parent.offlineJson.push({
									'operation':'<i onclick="deltr('+idx+')" class="layui-icon delicon">&#xe640;</i>',
									'stats':'<b data-stats="0">等待出库</b>',
									'barCode':obj.barCode,
									'commodityNumber':obj.commodityNumber,
									'commodityName':obj.commodityName,
									'homePhoto1':obj.homePhoto1,
									'merchantNumber':obj.merchantNumber,
									'locationId':obj.locationId,
									'theNum':obj.theNum,
									'discount':'1',
									'Total0':'0',
									'buyAmount':'1',
									'editStats':'0'//判断是否已经修改的参数
									
								})
//								parent.layui.table.reload('ORDERinTable'  );
//								console.log(parent.offlineJson.length)
//								parent.layui.table.reload();
								
							}else{
								stockInstr += '<tr><td onclick="deltr('+idx+')"><i class="layui-icon delicon">&#xe640;</i>   </td><td data-stats="0" >等待出库</td><td class="InBarCode" data-cId="'+obj.id+'">'+obj.barCode+'</td>'+
							'<td class="commodityNumber">'+obj.commodityNumber+'</td>'+
										'<td class="NowcommodityName">'+obj.commodityName+'</td>'+
										'<td>'+obj.homePhoto1+'</td>'+
										'<td class="NowmerchantNumber">'+obj.merchantNumber+'</td>'+
										'<td class="NowlocationId">'+obj.locationId+'</td>'+
										'<td >'+obj.theNum+'</td>'+
										'<td> <input class="editTinput NowtheNum" type="number" name="theNum" value="1"  max="'+obj.theNum+'" min="1"/ ></td></tr>';
							}
							
							
						}
			      	});
			      	parent.$("#stockinTable tbody").append(stockInstr);
			      	
			      	
			      	//图片点击放大
		            parent.TopimgFn();
				   	parent.layer.close(index);
				   	

			    }
			}
		
		
		}			      

		

	})

	//				layui.use(['layer', 'form', 'element', 'table', 'laydate'], function() {
	//					var layer = layui.layer,
	//						form = layui.form,
	//						element = layui.element,
	//						table = layui.table,
	//						laydate = layui.laydate;
	//
	//					// Stock_select = system/repository/select  ?page=1&pagesize=1采购入库-查
	//					var stockArray = new Array();
	//					
	//					function SNListFn(){
	//						
	//
	//					AjaxPostFn('system/repository/select?page=1&pagesize=11', "{}", function(jsonData) {
	//						//          console.log(jsonData.pageInfo.list[0].bizCommodityVo);
	//						$.each(jsonData.pageInfo.list, function(i, obj) {
	//							//            console.log(obj.bizCommodityVo)
	//							if(obj.bizRepository != null) {
	//								stockArray.push({
	//
	//									"operation": '<a class="layui-btn " lay-event="open1" >查看该产品库存周转率</a><a class="layui-btn layui-btn-normal " lay-event="open2" >查看该产品库存积压统计</a><a class="layui-btn layui-btn-danger " lay-event="delthis" >删除</a>',
	//									"idNum": '',
	//									"id": obj.bizRepository.id,
	//									"barCode": obj.bizRepository.barCode,
	//									"commodityBrand": obj.bizRepository.commodityName,
	//									"commodityOrigin": obj.bizRepository.commodityOrigin,
	//									"commodityPhoto": "<img src='" + obj.bizRepository.commodityPhoto + "' alt='头像小图' />",
	//									"commodityUnit": obj.bizRepository.commodityUnit,
	//									"commodityNum": "",
	//									"a4": "",
	//									"a5": "",
	//									"a6": "",
	//									"a7": "",
	//									"a8": "",
	//									"a9": ""
	//								});
	//							}
	//
	//						})
	//						console.log(stockArray)
	//							//展示已知数据
	//						table.render({
	//							elem: '#SNtable',
	//							cols: [
	//								[ //标题栏
	//								{field:'id',minWidth:'0%',width:'0%',type:'space',style:'display:none'}
	//								,{field:'operation', width:500,   title:'操作',sort: true }
	//				                ,{field:'idNum', width:60 , type:'numbers',  title:'序号',sort: true }
	//				                ,{field:'locationId', width:150 , title:'库存地点'}
	//				                ,{field:'theNum', width:200, title:'库存数量'} 
	//				                ,{field:'updateId', width:100 , title:'库存最后改动人'}
	//				                ,{field:'commodityNumber', width:100 , title:'库存最后改动时间'}
	//				                ,{field:'barCode', width:100 , title:'产品条形码'}
	//				                ,{field:'createTime', width:100 , title:'出货时间'}
	//				                ,{field:'merchantNumber', width:100 , title:'商家编号'}
	//				                ,{field:'commodityId', width:100 , title:'商品id'}
	//								]
	//							],
	//							data: stockArray,
	//							size: 'lg',
	//							even: true,
	//							page: true //是否显示分页
	//						});
	//
	//					});
	//					
	//					}//SNlist函数结束
	//					
	//					table.on('tool(table100)', function(obj) {
	//						var data = obj.data;
	//						console.log("当前库存的json数据:");
	//						console.log(data)
	//						if(obj.event === 'delthis') {
	//							//                      layer.msg('ID：'+ data.id + ' 的查看操作');
	//							layer.confirm('是否删除该条分类信息', function(index) {
	//								AjaxPostFn('system/repository/delete', "{'id':'" + data.id + "'}", function(jsonData) {
	//									if(jsonData.htmlState.status == 200) {
	//										layer.msg("删除成功");
	//
	//									} else {}
	//								})
	//								obj.del();
	//								layer.close(index);
	//
	//							});
	//						} else if(obj.event === 'open1') {
	//							layer.open({
	//
	//								skin: 'layui-layer-molv',
	//								title: '查看该产品库存周转率',
	//								area: ['720px', '500px'],
	//								content: $("#openbox1").html(),
	//								skin: 'demo-class',
	//								btn: ["关闭"],
	//								yes: function(index, layero) {
	//									//按钮1的回调
	//								},
	//								btn2: function(index, layero) {
	//									//按钮2的回调
	//								},
	//								cancel: function() {
	//									//右上关闭的回调
	//								}
	//							})
	//
	//						} else if(obj.event === 'open2') {
	//							layer.open({
	//
	//								skin: 'layui-layer-molv',
	//								title: '查看该产品库存积压统计',
	//								area: ['720px', '500px'],
	//								content: $("#openbox2").html(),
	//								skin: 'demo-class',
	//								btn: ["关闭"],
	//								yes: function(index, layero) {
	//									//按钮1的回调
	//								},
	//								btn2: function(index, layero) {
	//									//按钮2的回调
	//								},
	//								cancel: function() {
	//									//右上关闭的回调
	//								}
	//							})
	//						}
	//					});
	//
	//					var tab = parent.tab;
	//					$('a').off('click').on('click', function() {
	//						var _that = $(this),
	//							_data = {
	//								title: _that.data('title'),
	//								icon: _that.data('icon'),
	//								id: _that.data('id'),
	//								url: _that.data('url')
	//							};
	//						tab.tabAdd(_data);
	//					});
	//
	//				});
</script>
			</div>
			<!-- 概述 end-->
		</div>
	</body>

</html>